package com.huawei.appgallery.foundation.ui.css.adapter.type.factory;

import android.text.TextUtils;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSImage;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import o.Logger;
import o.dof;
import org.json.JSONObject;

public class CSSImageFactory implements CSSValueFactory {
    private static final String TAG = "CSSImageFactory";

    public CSSValue create(String str) {
        if (dof.ᐝ(str)) {
            return parser(str);
        }
        return new CSSImage(str);
    }

    private CSSImage parser(String str) {
        try {
            Object optString = new JSONObject(str).optString("url");
            if (!TextUtils.isEmpty(optString)) {
                return new CSSImage(optString);
            }
        } catch (Throwable e) {
            Logger.ˋ(TAG, "parser image parameter failed from: " + str, e);
        }
        return null;
    }
}
